/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package game;

/**
 *
 * @author Toan
 */
import java.io.*;
import java.net.*;

public class TriviaClient1 {
public static void main(String args[]) {
while (true) {
try {
    String msg = "";
//Socket client = new Socket("133.0.0.1", 1234);
    Socket client = new Socket(InetAddress.getLocalHost(),1234);
    InputStream clientIn = client.getInputStream();
    OutputStream clientOut = client.getOutputStream();
    PrintWriter pw = new PrintWriter(clientOut, true);
    BufferedReader br = new BufferedReader(new
    InputStreamReader(clientIn));
    BufferedReader stdIn = new BufferedReader(new
    InputStreamReader(System.in));
    System.out.println("Type \"request\" to see Questions and \"answer\" to answer: ");
    System.out.println("Bye to exit: ");
    msg = stdIn.readLine().trim();
    pw.println(msg);
/* get message from server */
    System.out.println(br.readLine());
    if (msg.equals("bye")) {
    break;
        }
    pw.close();
    br.close();
    client.close();
 } catch (ConnectException ce) {
    System.out.println("Cannot connect to the server.");
} catch (IOException ie) {
    System.out.println("I/O Error.");
    }
    }
    }
}